package cn.star.jots.filmActor.controller;

import cn.star.jots.base.response.JsonResult;
import cn.star.jots.filmActor.pojo.dto.FilmActorSaveParam;
import cn.star.jots.filmActor.pojo.vo.FilmActorVO;
import cn.star.jots.filmActor.service.FAService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/filmActor")
@Api(tags = "电影关联演员管理")
@Slf4j
public class FAController {
    @Autowired
    FAService faService;

    @GetMapping("/select/{filmId}")
    @ApiOperation(value = "根据电影id查询演员信息")
    public JsonResult selectByFilmId(@PathVariable Long filmId) {
        log.info("根据电影id查询演员信息:filmId={}", filmId);
        List<FilmActorVO> list = faService.selectByFilmId(filmId);
        return JsonResult.ok(list);
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存电影演员信息")
    public JsonResult save(FilmActorSaveParam filmActorSaveParam) {
        log.info("保存电影演员信息:filmActorSaveParam={}", filmActorSaveParam);
        faService.save(filmActorSaveParam);
        return JsonResult.ok();
    }

    @GetMapping("/select/selectById/{id}")
    @ApiOperation(value = "根据关联id查询演员信息")
    public JsonResult selectById(@PathVariable Long id) {
        log.info("根据关联id查询演员信息:id={}", id);
        List<FilmActorVO> list = faService.selectById(id);
        return JsonResult.ok(list);
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "根据关联id删除演员信息")
    public JsonResult delete(@PathVariable Long id) {
        log.info("根据关联id删除演员信息:id={}", id);
        faService.delete(id);
        return JsonResult.ok();
    }

    @DeleteMapping("/delete/film/{filmId}")
    @ApiOperation(value = "根据电影id删除演员信息")
    public JsonResult deleteByFilmId(@PathVariable Long filmId) {
        log.info("根据电影id删除演员信息:filmId={}", filmId);
        faService.deleteByFilmId(filmId);
        return JsonResult.ok();
    }
}
